﻿var app = angular.module('myApp', []);

app.controller('MainController', function ($scope) {
		//toggle customers
		$scope.customersVisible = false;
		$scope.toggleCustomers = function () {
				$scope.customersVisible = $scope.customersVisible ? false : true;
				
				if ($scope.itemsVisible == true) {
						$scope.itemsVisible = false;
				} 

				if ($scope.ordersVisible == true) {
						$scope.ordersVisible = false;
				} 
		}


		//toggle items
		$scope.itemsVisible = false;
		$scope.toggleItems = function () {
				$scope.itemsVisible = $scope.itemsVisible ? false : true;

				if ($scope.customersVisible == true) {
						$scope.customersVisible = false;
				}

				if ($scope.ordersVisible == true) {
						$scope.ordersVisible = false;
				}
		}

		//toggle orders
		$scope.ordersVisible = false;
		$scope.toggleOrders = function () {
				$scope.ordersVisible = $scope.ordersVisible ? false : true;

				if ($scope.customersVisible == true) {
						$scope.customersVisible = false;
				}

				if ($scope.itemsVisible == true) {
						$scope.itemsVisible = false;
				}
		}



});


//Controller to fetch Customers
app.controller('FetchCustomersController', function ($scope, CustomerService) {
		getCustomers();

		function getCustomers() {
				CustomerService.GetCustomers()
					.success(function (data) {
							$scope.customers = data;
					})
					.error(function (error) {
							$scope.message = error.message;
					});
		}
});


//Controller to fetch Orders
app.controller('FetchOrdersController', function ($scope, OrdersService) {

		getOrders();

		function getOrders() {
				OrdersService.GetOrders()
					.success(function (data) {
							$scope.orders = data;
					})
					.error(function (error) {
							$scope.message = error.message;
					});
		}
});


//Controller to fetch Items
app.controller('FetchItemsController', function ($scope, ItemsService) {

		getItems();

		function getItems() {
				ItemsService.GetItems()
					.success(function (data) {
							$scope.items = data;
					})
					.error(function (error) {
							$scope.message = error.message;
					});
		}
});





